Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update configure_multi_stage_inputs.jl #666

Merged
merged 1 commit into from
Apr 4, 2024
Merged

Conversation

sambuddhac
Copy link
Collaborator

@sambuddhac sambuddhac commented Mar 21, 2024

With introduction of init = 0 in summation terms to fix for bug encountered when summing over an empty array

Description

What type of PR is this? (check all applicable)

  • Bug Fix
  • Documentation Update
  • Performance Improvements

Related Tickets & Documents

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and .md files under /docs/src have been updated if necessary.
  • The latest changes on the target branch have been incorporated, so that any conflicts are taken care of before merging. This can be accomplished either by merging in the target branch (e.g. 'git merge develop') or by rebasing on top of the target branch (e.g. 'git rebase develop'). Please do not hesitate to reach out to the GenX development team if you need help with this.
  • Code has been tested to ensure all functionality works as intended.
  • CHANGELOG.md has been updated (if this is a 'notable' change).
  • I consent to the release of this PR's code under the GNU General Public license.

How this can be tested

Post-approval checklist for GenX core developers

After the PR is approved

  • Check that the latest changes on the target branch are incorporated, either via merge or rebase
  • Remember to squash and merge if incorporating into develop

@sambuddhac sambuddhac added the bug Something isn't working label Mar 21, 2024
@sambuddhac sambuddhac added this to the v0.4 milestone Mar 21, 2024
@sambuddhac sambuddhac requested a review from lbonaldo March 21, 2024 20:56
@sambuddhac sambuddhac self-assigned this Mar 21, 2024
@sambuddhac sambuddhac linked an issue Mar 21, 2024 that may be closed by this pull request
@sambuddhac sambuddhac marked this pull request as ready for review April 3, 2024 15:53
@lbonaldo lbonaldo force-pushed the sambuddhac-patch-4 branch from 1743739 to de926b1 Compare April 3, 2024 21:38
@lbonaldo lbonaldo changed the base branch from main to release/0.4.0 April 3, 2024 21:39
@lbonaldo lbonaldo force-pushed the sambuddhac-patch-4 branch 2 times, most recently from 1d9a0e9 to d9638c6 Compare April 3, 2024 21:54
Copy link
Collaborator

@lbonaldo lbonaldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Comment on lines 25 to 34
inv_costs_yr::Array,
crp::Array,
tech_wacc::Array)

# Check for resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years
if any((crp .== 0) .& (inv_costs_yr .> 0))
msg = "You have some resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years. " *
"These resources will have a calculated overnight capital cost of \$0. Correct your inputs if this is a mistake."
error(msg)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
inv_costs_yr::Array,
crp::Array,
tech_wacc::Array)
# Check for resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years
if any((crp .== 0) .& (inv_costs_yr .> 0))
msg = "You have some resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years. " *
"These resources will have a calculated overnight capital cost of \$0. Correct your inputs if this is a mistake."
error(msg)
end
inv_costs_yr::Array,
crp::Array,
tech_wacc::Array)
# Check for resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years
if any((crp .== 0) .& (inv_costs_yr .> 0))
msg = "You have some resources with non-zero investment costs and a Capital_Recovery_Period value of 0 years. " *
"These resources will have a calculated overnight capital cost of \$0. Correct your inputs if this is a mistake."
error(msg)
end

cur_stage = settings_d["CurStage"] # Current model
num_stages = settings_d["NumStages"] # Total number of model stages
stage_lens = settings_d["StageLengths"]

# 1) For each resource, find the minimum of the capital recovery period and the end of the model horizon
# Total time between the end of the final model stage and the start of the current stage
model_yrs_remaining = sum(stage_lens[cur_stage:end])
model_yrs_remaining = sum(stage_lens[cur_stage:end]; init=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
model_yrs_remaining = sum(stage_lens[cur_stage:end]; init=0)
model_yrs_remaining = sum(stage_lens[cur_stage:end]; init = 0)

Comment on lines 52 to 53
occ[i] = sum(inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i])
for p in 1:payment_yrs_remaining[i]; init=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
occ[i] = sum(inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i])
for p in 1:payment_yrs_remaining[i]; init=0)
occ[i] = sum(
inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i];
init = 0)

@lbonaldo lbonaldo force-pushed the sambuddhac-patch-4 branch from 2981978 to 6c2669d Compare April 4, 2024 15:17
src/multi_stage/configure_multi_stage_inputs.jl Outdated Show resolved Hide resolved
Comment on lines 52 to 53
occ[i] = sum(inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i])
for p in 1:payment_yrs_remaining[i]; init = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
occ[i] = sum(inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i])
for p in 1:payment_yrs_remaining[i]; init = 0)
occ[i] = sum(
inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i];
init = 0)

Comment on lines 53 to 55
inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i];
init = 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i];
init = 0)
inv_costs_yr[i] / (1 + tech_wacc[i]) .^ (p)
for p in 1:payment_yrs_remaining[i];
init = 0)

@lbonaldo lbonaldo force-pushed the sambuddhac-patch-4 branch from 6400edb to 939080b Compare April 4, 2024 15:42
@lbonaldo lbonaldo merged commit c53eb01 into release/0.4.0 Apr 4, 2024
7 checks passed
lbonaldo pushed a commit that referenced this pull request Apr 17, 2024
Add check on capital recovery period with non-zero investment cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Error calculating overnight capital cost when CRP is 0
2 participants